package com.back.end.config;

import com.back.end.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    /**
     * 添加jwt拦截器，并指定拦截路径
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                .excludePathPatterns("/App/user/sendSms")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/App/user/smsLogin")
                .addPathPatterns("/App/user/addAddress")
                .addPathPatterns("/App/user/getAddressList")
                .addPathPatterns("/App/user/checkUserInfo")
                .addPathPatterns("/order/**")
                .addPathPatterns("/Web/Product/**");
    }

    /**
     * jwt拦截器
     */
    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }
}
